package com.lzj.demo.jdbc;

import org.junit.Test;
import java.sql.*;

public class BrandUpdate {
    @Test
    public void test()throws Exception {
        //注册驱动
        Class.forName("com.mysql.jdbc.Driver");

        //获取连接
        String url = "jdbc:mysql://120.76.73.12:3306/db1?useSSL=false&useServerPrepStmts=true&characterEncoding=utf8";
        String username = "root";
        String password = "";
        Connection conn = DriverManager.getConnection(url, username, password);

        //定义update sql语句
        String updateSql = "update tb_brand set ordered = 2 where id = 2 ";
        //获取执行sql的对象Statement
        Statement statement = conn.createStatement();
        //执行sql并返回受影响行数
        int count = statement.executeUpdate(updateSql);
        if(count > 0){
            System.out.println("操作结果:成功修改了 "+count+" 行数据");
        }

        //释放资源
        statement.close();
        conn.close();
    }
}




